package org.sxf.app.sign.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.lidroid.xutils.util.LogUtils;

import org.sxf.app.sign.R;
import org.sxf.app.sign.data.DataCacheSingleton;


/**
 * Created by zqc on 16/5/9.
 */
public class SchoolListAdapter extends BaseAdapter {


    private LayoutInflater _inflater;
    public int _selectPosition;

    public SchoolListAdapter(LayoutInflater inflater){
        _inflater = inflater;
    }


    @Override
    public int getCount() {
        try {
            return DataCacheSingleton.getInstance().getSchoolBeanList().size();
        }catch (Exception e){
            return 0;
        }

    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LogUtils.d("getView:," + position);
        ViewHolder holder;
        //观察convertView随ListView滚动情况
        if (convertView == null) {
            convertView = _inflater.inflate(R.layout.item_school,null);
            holder = new ViewHolder();
            try {
                /**得到各个控件的对象*/
                holder.schoolName = (TextView) convertView.findViewById(R.id.school_name_text_view);
                holder.checkBoxImgView = (ImageView) convertView.findViewById(R.id.checkBoxImgView);
                convertView.setTag(holder);//绑定ViewHolder对象

                holder.schoolName.setText(DataCacheSingleton.getInstance().getSchoolBeanList().get(position).corp_name);

            }catch (NullPointerException e){
                //  e.printStackTrace();
            }catch (Exception e){
                //  e.printStackTrace();
            }


        }
        else{
            holder = (ViewHolder)convertView.getTag();//取出ViewHolder对象
        }



        if (_selectPosition == position){
            holder.checkBoxImgView.setImageResource(R.mipmap.black_item_select);
        }else {
            holder.checkBoxImgView.setImageResource(R.mipmap.empty);
        }



        return convertView;
    }


    public final class ViewHolder {
        public TextView schoolName;
        public ImageView checkBoxImgView;
    }
}
